Exercises

Hands on

Authors

Ellis Franklin

Elise Billoir

Published

February 6, 2025

Exercise 1 - Quarto basics

  1. Create a new Quarto HTML document using File > New File > Quarto Document
  2. Add a title and author in the YAML section at the top of the document
  3. Render the document
  4. Modify the YAML header to change the output format to docs
  5. Re-render your document
  6. What about PDF?

Exercise 2 - Markdown basics

Note

Before this exercise:

  1. Download the zip file ‘penguins-template’ thats holds
    • penguins-template.qmd file
    • three-penguins.png image
  2. Open the Rstudio and create a new project:
    • Go to File > New Project, then Browse to the downloaded zip file and Create.
  3. Copy and paste install.packages("palmerpenguins") into the Console and run it.
  1. Open the penguins-template.qmd file in RStudio

  2. Add a Level 2 header titled “Data Overview” after the existing content in the file

  3. Copy and paste the following text into the file:

    The `penguins` dataframe contains 344 observations of penguins.
    It includes several qualitative variables, including the following:
    - Sex of the penguins
    - Island where they are found
    - Species to which they belong
    The represented species are: Chinstrap, Gentoo, and Adélie.
  4. Modify the text so that the final rendering looks like this, with the value 344 inserted using inline code:

    The penguins penguins contains 344 observations of penguins. It includes several qualitative variables, including the following:

    • Sex of the penguins
    • Island where they are found
    • Species to which they belong

    The represented species are : Chinstrap, Gentoo et Adélie.

  5. Add the image three-penguins.png to your document, then add a caption for this image.

Exercise 3 - Code blocks and ouputs

  1. Add a code block to generate a table showing the first 5 rows of the penguins dataframe using the knitr::kable() function.
Tip

For those not familiar with R, unfold the following, copy and paste into the document, and render:

Code
knitr::kable(head(penguins))
  1. Add a second code block to generate a figure (using R base or ggplot2) to explore the relationship between the body mass of penguins and the length of their flippers, as well as the differences between species.
Tip

For those not familiar with R, unfold the following, copy and paste into the document and render:

Code
g <- ggplot(penguins, aes(x = flipper_length_mm, 
                              y = body_mass_g)) +
      geom_point(aes(color = species, shape = species), 
                 size = 2, 
                 alpha = 0.7) + 
      scale_color_manual(values = c("darkorange","purple","cyan4")) + 
      labs(x = "Flipper length (mm)", 
           y = "Body mass (g)", 
           color = "Penguin species", 
           shape = "Penguin species") + 
      theme_minimal()

g
  1. Add the following options to the code chunk, one by one. Generate the document after each modification and observe the changes:

    1. echo: false
    2. warning: false
  2. Just below the figure, provide a description of the relationship between the two variables, both overall and for each species.

  3. Modify the size of the figure using the following options, one by one. Re-render the document after each modification and describe how the figure changes:

    1. fig-width: 10
    2. fig-height: 3
    3. out-width: "100%"
    4. out-width: "20%"
  4. Add a label to the figure with the prefix fig-.

  5. Add a caption to the figure using the fig-cap chunk option. Re-render one last time.

Well done! You’ve just created your first Quarto report 🎉 !

Artwork from “Hello, Quarto” keynote by Julia Lowndes and Mine Çetinkaya-Rundel, presented at RStudio Conference 2022. Illustrated by Allison Horst.